//
//  UnderstandShapeMethod2.swift
//  SwiftUIShape
//
//  Created by 李煜 on 2024/7/31.
//

import SwiftUI

struct UnderstandShapeMethod2: View {
	var body: some View {
//		Path { p in
//			p.move(to: .zero)
//			p.addQuadCurve(to: CGPoint(x: 200, y: 0), control: CGPoint(x: 100, y: -20))
//			p.addRect(CGRect(x: 0, y: 0, width: 200, height: 40))
//		}
//		.fill(.green)
		
		Button(action: {
			
		}, label: {
			Text("Button")
				.font(.system(.title, design: .rounded))
				.bold()
				.foregroundStyle(.white)
				.frame(width: 250, height: 50)
        //使用自定义Dome
				.background(Dome().fill(Color.red))
		})
		.buttonStyle(ClickStyle())
		
	}
}

#Preview {
	UnderstandShapeMethod2()
}
struct ClickStyle: ButtonStyle {
	func makeBody(configuration: Configuration) -> some View {
		configuration.label
			.scaleEffect(configuration.isPressed ? 0.5 : 1.0)
	}
}

struct Dome: Shape {
  //遵守shape协议要实现path(in:)方法
	func path(in rect: CGRect) -> Path {
		var path = Path()
		path.move(to: .zero)
		path.addQuadCurve(to: CGPoint(x: rect.width, y: 0), control: CGPoint(x: rect.width/2.0, y: -rect.height * 1.9))
		path.addRect(CGRect(x: 0, y: 0, width: rect.width, height: rect.height))
		return path
		
	}
	
	
}
